import * as React from 'react';
import * as ReactDOM from 'react-dom';
import { createBrowserHistory } from 'history';
import { Redirect, Route, Router, Switch } from 'react-router';
import { LocalContext } from './context';
import './styles/page.less';
import LoadingLine from './components/load-line';

const HomePage = React.lazy(() => import(/* webpackChunkName: "page-home" */ './routes/home'));
const RunnerPage = React.lazy(() => import(/* webpackChunkName: "page-home" */ './routes/runner'));
const history = createBrowserHistory();

const contextData = {
  inject: {
    title: '微风测试中心',
    logo: '',
  },
  meta: [],
};
const App = () => {
  return (
    <React.Suspense fallback={<LoadingLine loading />}>
      <Router history={history}>
        <LocalContext.Provider value={contextData}>
          <Switch>
            <Route exact path="/runner" component={RunnerPage} />
            <Route exact path="/" component={HomePage} />
            <Redirect to="/" />
          </Switch>
        </LocalContext.Provider>
      </Router>
    </React.Suspense>
  );
};

ReactDOM.render(<App />, document.getElementById('root'));
